home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / BM192A.ZIP / ENGINE.S < prev    next >
Encoding:
Text File  |  1996-02-23  |  11.6 KB  |  384 lines

  1. *=======================================================*
  2. *    Display-engine: latest update 23/02/96        *
  3. *=======================================================*
  4. *    Call all display modules in correct order    *
  5. *=======================================================*
  6.  
  7. *-------------------------------------------------------*
  8.     txtlong
  9. *-------------------------------------------------------*
  10. display_engine:
  11. *-------------------------------------------------------*
  12. *    Calculate window base-address (centering)    *
  13. *-------------------------------------------------------*
  14.     move.l        ScreenLog,d0
  15.     move.w        width,d2
  16.     move.w        scrwidth,d1
  17.     tst.b        halfrows
  18.     beq.s        .no
  19.     add.w        d2,d2
  20. .no:    sub.w        d2,d1
  21.     lsr.w        d1
  22.     ext.l        d1
  23.     add.l        d1,d1
  24.     add.l        d1,d0
  25.     move.l        d0,screen
  26. *-------------------------------------------------------*
  27. *    Reset wall & floor buffers for this frame    *
  28. *-------------------------------------------------------*
  29.     move.l        #zone_space,zone_ptr
  30.     clr.b        zone_space
  31.     bsr        init_wall_lists
  32. *-------------------------------------------------------*
  33. *    Init display variables for this frame        *
  34. *-------------------------------------------------------*
  35.     bsr        update_display_struct
  36. *-------------------------------------------------------*
  37. *    Transfer frame-critical details to DSP        *
  38. *-------------------------------------------------------*
  39.     lea        display_struct,a6
  40.     move.l        sinpangle,d1
  41.     move.l        cospangle,d2
  42.     lsl.l        #8-2,d1
  43.     lsl.l        #8-2,d2
  44.     lea        DSPHostStat.w,a2
  45.     lea        DSPHost16.w,a0
  46.     moveq        #newscene_command,d0
  47.     dspwaitwrite    (a2)
  48.     move.w        d0,(a0)
  49.     dspwaitwrite    (a2)
  50.     move.w        display_px(a6),(a0)
  51.     dspwaitwrite    (a2)
  52.     move.w        display_py(a6),(a0)
  53.     dspwaitwrite    (a2)
  54.     move.w        pangle,(a0)
  55.     lea        DSPHost32.w,a0
  56.     dspwaitwrite    (a2)
  57.     move.l        d1,(a0)
  58.     dspwaitwrite    (a2)
  59.     move.l        d2,(a0)
  60. *-------------------------------------------------------*
  61. *    Init lighting effects for this frame        *    
  62. *-------------------------------------------------------*    
  63.     bsr        set_lighting
  64. *-------------------------------------------------------*
  65. *    Clearscreen for resizing window & debugging    *
  66. *-------------------------------------------------------*
  67. ;    move.b        #1,refresh
  68.     move.l        ScreenLog,a0
  69.     bsr        clearscreen
  70. *-------------------------------------------------------*
  71. *    Descend BSP tree & build scenery        *
  72. *-------------------------------------------------------*
  73.     bsr        descend_bsp
  74. *-------------------------------------------------------*
  75. *    Render floors & ceilings            *
  76. *-------------------------------------------------------*
  77.     bsr        render_flats
  78. *-------------------------------------------------------*
  79. *    Render transparet wall & sprite segments    *
  80. *-------------------------------------------------------*
  81. ;    bsr        render_walls
  82. *-------------------------------------------------------*
  83.     rts
  84.  
  85. *-------------------------------------------------------*
  86. *    Init wall edgebuffer lists for next frame    *
  87. *-------------------------------------------------------*
  88.     txtlong
  89. *-------------------------------------------------------*
  90. init_wall_lists:
  91. *-------------------------------------------------------*
  92.     lea        maxy,a0
  93.     lea        miny,a1
  94.     move.w        height,d1
  95.     moveq        #0,d2
  96.     moveq        #-1,d3
  97.     move.w        width,d0
  98.     subq.w        #1,d0
  99.     lea        occlusion_list,a2
  100. .for_i:    move.w        d1,(a0)+
  101.     move.w        d2,(a1)+
  102.     move.b        d3,(a2)+
  103.     dbra        d0,.for_i
  104.     clr.w        wallruncount
  105.     move.w        width,columns
  106.     rts
  107.  
  108. *-------------------------------------------------------*
  109. *    Set up general (engine) structures & tables    *
  110. *-------------------------------------------------------*
  111.     txtlong
  112. *-------------------------------------------------------*
  113. init_displaystruct:
  114. *-------------------------------------------------------*
  115.     lea        display_struct,a6
  116. *-------------------------------------------------------*
  117. *    Initialise pointers to WAD room data        *
  118. *-------------------------------------------------------*
  119.     move.l        PNode_Array,display_nodes(a6)
  120.     move.l        Seg_Array,display_segs(a6)
  121.     move.l        Sector_Array,display_sectors(a6)
  122.     move.l        SSector_Array,display_ssectors(a6)
  123.     move.l        Side_Array,display_sidedefs(a6)
  124.     move.l        Line_Array,display_linedefs(a6)
  125.     move.l        Vertex_Array,display_vertices(a6)
  126.     rts
  127.  
  128. *-------------------------------------------------------*
  129. *    Update general (engine) display structure    *
  130. *-------------------------------------------------------*
  131.     txtlong
  132. *-------------------------------------------------------*
  133. update_display_struct:
  134. *-------------------------------------------------------*
  135.     lea        display_struct,a6
  136. *-------------------------------------------------------*
  137. *    Set up player position and angle        *
  138. *-------------------------------------------------------*
  139.     move.l        sinpangle,d3
  140.     move.l        cospangle,d4
  141.     asr.l        #2,d3
  142.     asr.l        #2,d4
  143.     move.w        d3,display_sina(a6)
  144.     move.w        d4,display_cosa(a6)
  145.     move.w        px,display_px(a6)
  146.     move.w        py,display_py(a6)
  147. *-------------------------------------------------------*
  148. *    Calculate base address of octant routine    *
  149. *-------------------------------------------------------*
  150.     st        first_ssector
  151. *-------------------------------------------------------*
  152.     rts
  153.     
  154. *-------------------------------------------------------*
  155. *    Select new display window size            *
  156. *-------------------------------------------------------*
  157.     txtlong
  158. *-------------------------------------------------------*
  159. select_window:
  160. *-------------------------------------------------------*
  161.     pushall
  162.     moveq        #10,d1
  163.     move.w        window_size,d2
  164.     cmp.w        #256,d2
  165.     bpl.s        .ok1
  166.     move.w        #256,d2
  167. .ok1    cmp.w        #1<<10,d2
  168.     bmi.s        .ok2
  169.     move.w        #1<<10,d2
  170. .ok2:    move.w        d2,window_size
  171. *-------------------------------------------------------*
  172. *    Recalculate window size                *
  173. *-------------------------------------------------------*
  174.     move.w        d2,d3
  175.     move.w        d2,d4
  176.     mulu.w        viewport_width,d3
  177.     mulu.w        viewport_height,d4
  178.     lsr.l        d1,d3
  179.     lsr.l        d1,d4
  180.     tst.b        halfrows
  181.     beq.s        .nhr1
  182.     lsr.w        d3
  183. .nhr1:    tst.b        halflines
  184.     beq.s        .nhl1
  185.     lsr.w        d4
  186. .nhl1:    move.w        d3,width
  187.     move.w        d4,height
  188. *-------------------------------------------------------*
  189. *    Recalculate aspect ratio            *
  190. *-------------------------------------------------------*
  191.     move.w        d3,d5
  192.     move.w        d4,d6
  193.     ext.l        d6
  194.     move.w        viewport_width,d0
  195.     mulu.w        aspect_ratio,d0
  196.     mulu.l        d0,d6
  197.     move.w        #default_width,d0
  198.     mulu.w        viewport_height,d0
  199.     divu.l        d0,d6
  200.     move.w        d6,rheight
  201. *-------------------------------------------------------*
  202. *    Recalculate texture ratio (1:1 or 2:1 or 1:2)    *
  203. *-------------------------------------------------------*
  204.     lsr.w        d5
  205.     move.w        d5,d0
  206.     tst.b        halfrows
  207.     beq.s        .nhr2
  208.     lsl.w        d0
  209. .nhr2:    tst.b        halflines
  210.     beq.s        .nhl2
  211.     lsr.w        d0
  212. .nhl2:    move.w        d5,hscale
  213.     mulu.w        aspect_ratio,d0
  214.     divu.w        #base_aspect,d0
  215.     move.w        d0,vscale
  216. *-------------------------------------------------------*
  217. *    Update global display structure            *
  218. *-------------------------------------------------------*
  219.     lea        display_struct,a6
  220.     move.w        width,d1
  221.     move.w        d1,display_width(a6)
  222.     lsr.w        d1
  223.     move.w        d1,display_hwid(a6)
  224.     move.w        height,d1
  225.     move.w        d1,display_height(a6)
  226.     lsr.w        d1
  227.     move.w        d1,display_hhig(a6)
  228.     move.w        rheight,display_rheight(a6)
  229.     move.w        hscale,display_hscale(a6)
  230.     move.w        vscale,display_vscale(a6)
  231. *-------------------------------------------------------*
  232. *    Update addwall structure            *
  233. *-------------------------------------------------------*
  234.     lea        addwall_struct,a6
  235.     move.w        width,d1
  236.     move.w        d1,addwall_width(a6)
  237.     lsr.w        d1
  238.     move.w        d1,addwall_hwid(a6)
  239.     move.w        height,d1
  240.     move.w        d1,addwall_height(a6)
  241.     lsr.w        d1
  242.     move.w        d1,addwall_hhig(a6)
  243.     move.w        rheight,addwall_rheight(a6)
  244.     move.w        hscale,addwall_hscale(a6)
  245.     move.w        vscale,addwall_vscale(a6)
  246. *-------------------------------------------------------*
  247. *    3 CLS calls required to wipe log, phys & bak    *
  248. *-------------------------------------------------------*
  249.     move.b        #3,refresh
  250. *-------------------------------------------------------*
  251. *    Recalculate video display height        *
  252. *-------------------------------------------------------*
  253.     move.b        #1,adjust
  254. *-------------------------------------------------------*
  255. *    Resize DSP rendering zone            *
  256. *-------------------------------------------------------*
  257.     bsr        dsp_resizewindow
  258. *-------------------------------------------------------*
  259.     bsr        adjust_map
  260. *-------------------------------------------------------*
  261.     popall
  262.     rts
  263.  
  264. *-------------------------------------------------------*
  265. *    Command DSP to resize internal structures    *
  266. *-------------------------------------------------------*
  267.     txtlong
  268. *-------------------------------------------------------*
  269. dsp_resizewindow:
  270. *-------------------------------------------------------*
  271.     lea        DSPHostStat.w,a2
  272.     lea        DSPHost16.w,a0
  273.     moveq        #resize_command,d0
  274.     dspwaitwrite    (a2)
  275.     move.w        d0,(a0)
  276.     dspwaitwrite    (a2)
  277.     move.w        width,(a0)
  278.     dspwaitwrite    (a2)
  279.     move.w        height,(a0)
  280.     dspwaitwrite    (a2)
  281.     move.w        rheight,(a0)
  282.     dspwaitwrite    (a2)
  283.     move.w        hscale,(a0)
  284.     dspwaitwrite    (a2)
  285.     move.w        vscale,(a0)
  286. *-------------------------------------------------------*
  287. *    Clear structures with dummy new_ssector        *
  288. *-------------------------------------------------------*
  289.     moveq        #newssector_command,d0
  290.     dspwaitwrite    (a2)
  291.     move.w        d0,(a0)
  292.     rts
  293.         
  294. *-------------------------------------------------------*
  295. *    Wipe framebuffer                *
  296. *-------------------------------------------------------*
  297.     txtlong
  298. *-------------------------------------------------------*
  299. clearscreen:
  300. *-------------------------------------------------------*
  301.     tst.b        refresh
  302.     bne.s        .go
  303.     rts
  304. .go:    subq.b        #1,refresh
  305.     move.w        #320/2,d0
  306.     mulu.w        viewport_height,d0
  307. *-------------------------------------------------------*
  308. clearlongs:
  309. *-------------------------------------------------------*
  310.     moveq        #0,d1
  311.     move.l        d1,d2
  312.     move.l        d2,d3
  313.     move.l        d2,d4
  314.     move.l        d2,d5
  315.     move.l        d2,d6
  316.     move.l        d2,d7
  317.     move.l        d2,a2
  318.     move.l        d2,a3
  319.     moveq        #128-1,d1
  320.     and.l        d0,d1
  321.     bra.s        .strt
  322. .long    move.l        d2,(a0)+
  323. .strt    dbra        d1,.long
  324.     lsr.l        #7,d0
  325.     move.l        d0,d1
  326.     lsl.l        #8,d1                ; *256
  327.     lsl.l        #1,d1                ; *2    =  *512
  328.     add.l        d1,a0
  329.     bra.s        .next
  330. .clr    movem.l        d2-d7/a2-a3,-(a0)        ; 4*8*16 = 512
  331.     movem.l        d2-d7/a2-a3,-(a0)
  332.     movem.l        d2-d7/a2-a3,-(a0)
  333.     movem.l        d2-d7/a2-a3,-(a0)
  334.     movem.l        d2-d7/a2-a3,-(a0)
  335.     movem.l        d2-d7/a2-a3,-(a0)
  336.     movem.l        d2-d7/a2-a3,-(a0)
  337.     movem.l        d2-d7/a2-a3,-(a0)
  338.     movem.l        d2-d7/a2-a3,-(a0)
  339.     movem.l        d2-d7/a2-a3,-(a0)
  340.     movem.l        d2-d7/a2-a3,-(a0)
  341.     movem.l        d2-d7/a2-a3,-(a0)
  342.     movem.l        d2-d7/a2-a3,-(a0)
  343.     movem.l        d2-d7/a2-a3,-(a0)
  344.     movem.l        d2-d7/a2-a3,-(a0)
  345.     movem.l        d2-d7/a2-a3,-(a0)
  346. .next    dbra        d0,.clr
  347.     rts
  348.  
  349. *-------------------------------------------------------*
  350. *    Doom engine subroutines                *
  351. *-------------------------------------------------------*
  352.  
  353.     include        bspd.s
  354.     include        shards.s
  355.     include        render.s
  356.     include        lighting.s
  357.     include        timing.s
  358.     include        tables.s
  359.  
  360. *-------------------------------------------------------*
  361.             datlong
  362. *-------------------------------------------------------*
  363.  
  364. viewport_width:        dc.w    default_width        ; window width
  365. viewport_height:    dc.w    default_height        ; window height
  366. aspect_ratio:        dc.w    240            ; vertical aspect
  367.     
  368. *-------------------------------------------------------*
  369.             bsslong
  370. *-------------------------------------------------------*
  371.  
  372. display_struct:        ds.b    display_len        ; general display structure
  373.  
  374. window_size:        ds.w    1            ; window size % factor
  375. width:            ds.w    1            ; current render-width
  376. height:            ds.w    1            ; current render-height
  377. rheight:        ds.w    1            ; [relative] aspect ratio height
  378. hscale:            ds.w    1            ; horizontal x-scaling factor
  379. vscale:            ds.w    1            ; vertical x-scaling factor
  380.  
  381. *-------------------------------------------------------*
  382.             txtlong
  383. *-------------------------------------------------------*
  384.